/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_httpd.htm
 *
 * Zhiqim Httpd is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.httpd.validate.onex;

import org.zhiqim.httpd.util.Scripts;
import org.zhiqim.httpd.validate.OneValidate;
import org.zhiqim.kernel.annotation.AnAlias;
import org.zhiqim.kernel.util.Validatex;

/**
 * 验证是否身份证号
 *
 * @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
 */
@AnAlias("IsIdcard")
public class IsIdcard extends OneValidate
{
    /** 默认构造 */
    public IsIdcard(String field, String alert)
    {
        super(field, alert);
    }
    
    /** 构造函数，支持把错误信息传到elementId中 */
    public IsIdcard(String field, String alert, String elementId)
    {
        super(field, alert, elementId);
    }
    
    /** 默认构造，支持判断是否允许为空 */
    public IsIdcard(String field, String alert, boolean allowEmpty)
    {
        super(field, alert, allowEmpty);
    }
    
    /** 构造函数，支持判断是否允许为空，支持判断是否响应焦点 */
    public IsIdcard(String field, String alert, boolean allowEmpty, boolean isFocus)
    {
        super(field, alert, allowEmpty, isFocus);
    }
    
    /** 构造函数，支持判断是否允许为空，支持把错误信息传到elementId中 */
    public IsIdcard(String field, String alert, boolean allowEmpty, String elementId)
    {
        super(field, alert, allowEmpty, elementId);
    }
    
    /** 获取该验证的名称 */
    public String getName()
    {
        return IDCARD;
    }
    
    /** 服务端验证 */
    public boolean validate(String value)
    {
        return Validatex.isIdcard(value, allowEmpty);
    }
    
    /** 获取该验证的函数 */
    public String getFunction()
    {
        return Scripts.isIdcard(allowEmpty);
    }

    /** 获取该验证的判断代码 */
    public String getScript()
    {
        return Scripts.buildValidateScript(IDCARD, field, alert, elementId, isFocus);
    }
}
